package com.google.code.twiddling.core.chain;

import com.google.code.twiddling.core.clp.CommandLineParser;
import com.google.code.twiddling.core.command.CommandMetadata;
import com.google.code.twiddling.core.command.ICommand;
import com.google.code.twiddling.core.command.CommandContext;
import com.google.code.twiddling.core.exception.TwiddlingException;

/**
 * @author <a href="mailto:yy.young@gmail.com">Young Yang</a>
 * @create Dec 16, 2008 11:25:58 AM
 */
public class CommandLineParserProcessor extends Processor {

    protected void process(CommandContext commandContext) throws TwiddlingException { 	
    	CommandMetadata data = commandContext.getMetadata();
        ICommand command = commandContext.getCommandRegistry().newCommandInstance(data.getName());
        commandContext.setCommand(command);
        CommandLineParser clp = new CommandLineParser(commandContext.getCommand());
        clp.setStopAtNonOption(false);
        clp.process(data.getParameters());
    }

}
